package assets_withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/base-common/headInfo"
	"gitee.com/liuxuezhan/ar-platform/base-common/pkg/xcode"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type WithdrawSuccessLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// b端财务管理页面--提现记录--人工确认
func NewWithdrawSuccessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawSuccessLogic {
	return &WithdrawSuccessLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WithdrawSuccessLogic) WithdrawSuccess(req *types.WithdrawSuccessReq) (resp *types.WithdrawSuccessRes, err error) {
	UserId := headInfo.GetTokenUid(l.ctx)
	if UserId == 0 {
		return nil, xcode.UserNotFound
	}

	rpc_req := &rpc.SuccessWithDrawReq{
		OrderNo: req.Order_no,
	}

	// 发送请求
	_, err = l.svcCtx.AssetsRpc.PayWithdraw.WithdrawSuccess(l.ctx, rpc_req)
	if err != nil {
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.WithdrawSuccessRes{}
	resp.WithDraw = types.WithDraw{}
	return
}
